import {createRouter, createWebHashHistory} from 'vue-router';
import Creation from '../views/Creation.vue';
import ImageGen from "../views/ImageGen.vue";
import AiChat from "../views/AiChat.vue";
import Login from "../views/Login.vue";
import layout_user from "../layouts/Layout_User.vue";
import layout_admin from "../layouts/Layout_Admin.vue"
import AiManage from "../views/AiManage.vue";
import CreationSquare from "../views/CreationSquare.vue";
import CreationDetail from "../views/CreationDetail.vue";
import AiTalk from "../views/AiTalk.vue";
import UserManage from "../views/UserManage.vue";
import CreationList from "../views/CreationList.vue";
import AiAnalysis from "../views/AiAnalysis.vue";
import AiSearch from "../views/AiSearch.vue";
import aiAnalysis from "../views/AiAnalysis.vue";
import Chart from "../views/Chart.vue";
import FollowList from "../views/FollowList.vue";
import Chat from "../views/Chat.vue"
const routes = [
    {
        path: '/',
        redirect: '/login'  // 访问根路径时跳转到登录页
    },
    {
        path: '/layout_user',
        component: layout_user,
        redirect: '/layout_user/creation',  // 修正重定向路径
        children: [
            {
                path: 'creation',  // 子路由使用相对路径，不要加/
                name: 'CreationUser',
                component: Creation
            },
            {
                path: 'imageGen',  // 子路由使用相对路径
                name: 'ImageGenUser',
                component: ImageGen,
            },
            {
                path: 'aiChat',  // 子路由使用相对路径
                name: 'AiChatUser',
                component: AiChat,
            },
            {
                path: 'creationSquare',  // 子路由使用相对路径
                name: 'CreationSquareUser',
                component: CreationSquare,
                meta: { keepAlive: true }
            },
            {
                path: ':sId', // 带参数的详情页路由
                name: 'CreationDetailUser',
                component: CreationDetail,
                props: true // 允许将路由参数作为props传递给组件
            },
            {
                path: 'aiAnalysis',
                name: 'AiAnalysisUser',
                component: AiAnalysis,
            },
            {
                path: 'aiSearch',
                name: 'AiSearchUser',
                component: AiSearch,
                meta: { keepAlive: true }
            },
            {
                path:'creationlist',
                name: 'CreationListUser',
                component: CreationList,
            },
            {
                path:'followList',
                name: 'FollowListUser',
                component: FollowList,
            },
            {
                path: 'chat',
                name: 'ChatUser',
                component: Chat
            },
        ]
    },
    {
        path: '/layout_admin',
        component: layout_admin,
        redirect: '/layout_admin/aiManage',
        children: [
            {
                path: 'aiManage',
                name: 'AiManage',
                component: AiManage
            },
            {
                path: 'aiTalk',
                name: 'AiTalk',
                component: AiTalk
            },
            // 公共页直接拷贝过来
            {
                path: 'creation',
                name: 'Creation',
                component: Creation
            },
            {
                path: 'imageGen',
                name: 'ImageGen',
                component: ImageGen
            },
            {
                path: 'aiChat',
                name: 'AiChat',
                component: AiChat
            },
            {
                path: 'userManage',  // 子路由使用相对路径
                name: 'UserManage',
                component: UserManage,
            },
            {
                path:'creationlist',
                name: 'CreationList',
                component: CreationList,
                meta: { keepAlive: true }
            },
            {
                path: 'creationSquare',
                name: 'CreationSquare',
                component: CreationSquare,
                meta: { keepAlive: true }
            },
            {
                path: ':sId', // 带参数的详情页路由
                name: 'CreationDetail',
                component: CreationDetail,
                props: true
            },
            {
                path:'followList',
                name: 'FollowList',
                component: FollowList,
            },
            {
                path: 'aiSearch',
                name: 'AiSearch',
                component: AiSearch,
                meta: { keepAlive: true }
            },
            {
                path: 'aiAnalysis',
                name: 'AiAnalysis',
                component: aiAnalysis,
            },
            {
                path: 'chart',
                name: 'Chart',
                component: Chart
            },
        ]
    },
    {
        path: '/login',
        name: 'Login',
        component: Login
    }
]
const router = createRouter({
    routes,
    history: createWebHashHistory(),
    // history: createWebHistory()
})

// router.beforeEach((to,from,next)=>{
//     if(to.meta.needLogin &&  sessionStorage.getItem('user')==null){
//         alert("请先登录");
//         next("/login");
//     }else{
//         next();
//     }
// })


export default router;